home *** CD-ROM | disk | FTP | other *** search
/ Amiga Games: Greatest Hits 1996 / Amiga Games: Greatest Hits 1996.iso / rexx / update.rexx < prev    next >
OS/2 REXX Batch file  |  1995-09-14  |  4KB  |  151 lines

  1. /* This is a demo script showing how to perform a relational update under direct arexx control
  2.     (The same could also be done from the Update window without programming, but this script can be
  3.      used as a skelleton if more advanced updates are needed)
  4.  
  5.     The program will look for two files TWIST:upd_customer and TWIST:upd_sales if not alreade
  6.     present the files will be created with a few dummy records
  7.  
  8.     The customer file holds information on customers. 
  9.     The TotalSales should tell the total monetary amount    purchased for so far.
  10.  
  11.     The sales file holds information on sale. 
  12.     The Cnr field is used to identify the customer to whom the item was sold.
  13.     The TotalFlag is TRUE if the sales amount has already been totaled in the customer file
  14.     
  15.     The program goes trough all the sales records not already processed.
  16.     For each sales record a nested SELECTALL in the customer file is performed to find the
  17.     customer record. The Pprice multiplied by Units is added to the customer.TotalSales field.
  18.     Finally the TotalFlag is set to TRUE to ensure that the sales record it not used again the
  19.     next time the arexx script is run.
  20.     
  21.     
  22.     Try running the arexx script
  23.     Then open the two created DB files and add a few new sales records by hand and run the arexx program again.
  24.     The manually added records will now also be totaled in the customer file.
  25.     
  26.     Beware that the program does not perform any safety check of onfound customers
  27.     Try yourself to refine it by adding an error check after line 129 (the SELECTALL in the customer file)
  28.     
  29.  
  30.     Hasse Wehner, Mermaid Group
  31. */
  32.  
  33. options results
  34. address twist
  35. custfilename = "TWIST:upd_customer"
  36.  
  37. open custfilename
  38. exit
  39.  
  40.  
  41.  
  42.  
  43. salesfilename = "TWIST:upd_sales"
  44.  
  45. if exists(custfilename || ".DB") == 1 then OPEN custfilename
  46. else
  47. do
  48.     CREATEDB custfilename
  49.     CREATEFIELD "Cnr" INTEGER
  50.     CREATEFIELD "Name"
  51.     CREATEFIELD "Address" 50
  52.     CREATEFIELD "TotalSales" NUMBER ZERO
  53.     ENDCREATEDB
  54.     open custfilename
  55.     if RC!=0 then
  56.         do
  57.         say "unable to create " custfilename
  58.         exit
  59.     end
  60.  
  61.     customer.Cnr = "1"
  62.     customer.Name = "Jones, Bill"
  63.     customer.Address = "5th avenue 123, N.Y, USA"
  64.     INSERT stem customer
  65.  
  66.     customer.Cnr = "2"
  67.     customer.Name = "Smith, David"
  68.     customer.Address = "The silent road 1, Dublin, Ireland"
  69.     INSERT stem customer
  70.  
  71.     customer.Cnr = "3"
  72.     customer.Name = "Josephson, Gary"
  73.     customer.Address = "Ryesgade 100, Copenhagen, Denmark"
  74.     INSERT stem customer
  75.  
  76. end
  77.  
  78. if exists(salesfilename || .DB) == 1 then open salesfilename
  79. else
  80. do
  81.     CREATEDB salesfilename
  82.     CREATEFIELD "Cnr" INTEGER
  83.     CREATEFIELD "Pnr" INTEGER
  84.     CREATEFIELD "Ptext" 
  85.     CREATEFIELD "Pprice" NUMBER
  86.     CREATEFIELD "Units" INTEGER
  87.     CREATEFIELD "TotalFlag" INTEGER ZERO
  88.     ENDCREATEDB
  89.     open salesfilename
  90.     if RC!=0 then
  91.     do
  92.         say "unable to create " salesfilename
  93.         exit
  94.     end
  95.     
  96.     sales.Cnr = "1"
  97.     sales.Pnr = "101"
  98.     sales.Ptext = "Twist2"
  99.     sales.Pprice = "299"
  100.     sales.Units = "1"
  101.     INSERT stem sales
  102.         
  103.     sales.Cnr = "2"
  104.     sales.Pnr = "102"
  105.     sales.Ptext = "OS3.1 upgrade"
  106.     sales.Pprice = "78"
  107.     sales.Units = "1"
  108.     INSERT stem sales
  109.         
  110.     sales.Cnr = "1"
  111.     sales.Pnr = "103"
  112.     sales.Ptext = "Floppies"
  113.     sales.Pprice = "2.50"
  114.     sales.Units = "20"
  115.     INSERT stem sales
  116.         
  117.     sales.Cnr = "3"
  118.     sales.Pnr = "102"
  119.     sales.Ptext = "OS3.1 upgrade"
  120.     sales.Pprice = "78"
  121.     sales.Units = "1"
  122.     INSERT stem sales
  123.         
  124.     sales.Cnr = "2"
  125.     sales.Pnr = "101"
  126.     sales.Ptext = "Twist2"
  127.     sales.Pprice = "299"
  128.     sales.Units = "1"
  129.     INSERT stem sales
  130.         
  131. end
  132.  
  133. exit
  134. SELECTALL WHERE "!TotalFlag" STEM sales /* only select those sales records who haven't yet been totalled */
  135. do while RC==0
  136.     /* Go trough all records in the sales file */
  137.     OPEN custfilename    /* make the customer file the current file */
  138.     SELECTALL WHERE '"' || "Cnr == " || sales.Cnr || '"' STEM customer
  139.     customer.TotalSales = customer.TotalSales + sales.Units * sales.Pprice
  140.     CHANGE "TotalSales" as customer.TotalSales
  141.     if RC!=0 then break
  142.  
  143.     OPEN salesfilename        /* make the sales file the current file */
  144.     CHANGE "TotalFlag" as "1"  /* now the record will not be included the next time update.rexx is run */
  145.     SELECTNEXT
  146. end
  147.  
  148. CLOSE salesfilename
  149. CLOSE custfilename
  150.  
  151.